//
//  Kylin_PopMenu.m
//  01-LotteryBaseFrame
//
//  Created by Kylin on 16/1/5.
//  Copyright © 2016年 kylin. All rights reserved.
//
#define Kylin_KeyWindow [UIApplication sharedApplication].keyWindow
#import "Kylin_PopMenu.h"

@implementation Kylin_PopMenu

// 1:如果点击了关闭按钮,就会通知代理执行代理方法
- (IBAction)closeBtnOnClick:(id)sender {
    
    
    if ([self.delegate respondsToSelector:@selector(popMenuDidOnClick:)]) {
        [self.delegate popMenuDidOnClick:self];
    }
}

+ (instancetype)showInCenter:(CGPoint)center{
    Kylin_PopMenu *popMenu = [[NSBundle mainBundle]loadNibNamed:NSStringFromClass(self) owner:nil options:nil][0];
    popMenu.center = center;
    
    [Kylin_KeyWindow addSubview:popMenu];
    return popMenu;
}

- (void)hideInCenter:(CGPoint)center completion:(Myblock)completion{
    // 4:接收代理传过来的中心点
    [UIView animateWithDuration:0.5 animations:^{
        
        // 改变popMuenu的大小比例
        self.transform = CGAffineTransformMakeScale(0.01, 0.01);
        // 移动popMuenu的位置
        self.center = center;
    }completion:^(BOOL finished) {
        // 执行完后移除popMuenu
        [self removeFromSuperview];
        
        
        // 如果block有值,那么就会执行
        if (completion) {
            completion();
        }
    }];
}
@end
